package com.mf.morefun.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mf.morefun.R;
import com.zhcx.zhcxlibrary.utils.DeviceUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TestListenSelectCharAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> wordList;

    public TestListenSelectCharAdapter(Context mContext, List<String> wordList) {
        this.mContext = mContext;
        this.wordList = wordList;
    }

    @Override
    public int getCount() {
        return wordList.size();
    }

    @Override
    public Object getItem(int position) {
        return wordList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.layout_listenselectchar, null);
        } else {
            view = convertView;
        }
        if (null != wordList && wordList.size() > 0){
            ViewHolder holder = new ViewHolder(view);
            ViewGroup.LayoutParams params = holder.ivImg.getLayoutParams();
            if(null != params){
                params.height = DeviceUtils.dip2px(mContext, 60);
                params.width = DeviceUtils.dip2px(mContext, 60);
            }else {
                params = new ViewGroup.LayoutParams(DeviceUtils.dip2px(mContext, 60), DeviceUtils.dip2px(mContext, 60));
            }
            holder.ivImg.setLayoutParams(params);
            holder.ivImg.setText(wordList.get(position));
        }
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.iv_img)
        TextView ivImg;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
